package cn.lili.modules.system.entity.dto;

import cn.lili.common.utils.StringUtils;
import cn.lili.common.vo.PageVO;
import cn.lili.modules.system.entity.dos.LiAuthSpaceGoods;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.poi.ss.formula.functions.T;

import java.io.Serial;
import java.util.List;

/**
 * 授权空间商品分页查询参数
 */
@Data
public class SpaceGoodsSearchParams extends PageVO {
    @Serial
    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = " 商品名称")
    private String goodsName;

    @ApiModelProperty(value = "商品id")
    private String goodsId;

    @ApiModelProperty(value = "空间 id")
    private String authSpaceId;

    @ApiModelProperty(value = "空间 id 多个")
    private List<String> spaceIds;

    @ApiModelProperty(value = "空间 code")
    private String authSpaceCode;

    @ApiModelProperty(value = "排序")
    @TableField("sort")
    private String sort;

    public LambdaQueryWrapper<LiAuthSpaceGoods> queryWrapper(){
        return new LambdaQueryWrapper<LiAuthSpaceGoods>().like(StringUtils.isNotEmpty(goodsName),LiAuthSpaceGoods::getGoodsName,goodsName)
                .eq(StringUtils.isNotEmpty(goodsId),LiAuthSpaceGoods::getGoodsId,goodsId)
                .eq(StringUtils.isNotEmpty(authSpaceId),LiAuthSpaceGoods::getAuthSpaceId,authSpaceId)
                .in(spaceIds != null && !spaceIds.isEmpty(),LiAuthSpaceGoods::getAuthSpaceId,spaceIds)
                .eq(StringUtils.isNotEmpty(authSpaceCode),LiAuthSpaceGoods::getAuthSpaceCode,authSpaceCode)
                .orderByAsc(LiAuthSpaceGoods::getSort).orderByDesc(LiAuthSpaceGoods::getCreateTime).orderByDesc(LiAuthSpaceGoods::getId);
    }
}
